import AMapLoader from "@amap/amap-jsapi-loader";
import china from "/@/assets/lngLat/china.ts";
import chinaInner from "/@/assets/lngLat/chinaInner.ts";
import { Callback, ExtDataType, InitMap, MarkerOption, ResultType } from '/@/assets/mapUtils/mapFunTypes.ts';
import { defaultOption, getZoom, mapKey, mapPlugin } from "/@/assets/mapUtils/mapConstant.ts";

let AMap = null;
export const Map = {
    map: null,
    overlayGroup: null, // 地图中marker
    circleGroup: null, //直升机背景圆
    cluster: null, //直升机marker点聚合图层
    airMarkerList: [], //直升机markerList
    placeSearch: null, //地点查询
    marker: null, // 健康终端报警
    infoWindow: null, //地图弹窗
    /**
     * @desc 地图舒适化
     * @param el dom元素 id选择器
     * @param option 地图配置
     */
    initMap({ el, option }: InitMap) {
        return new Promise((resolve) => {
            AMapLoader.load({
                key: mapKey, // 申请好的Web端开发者Key，首次调用 load 时必填
                version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
                plugins: mapPlugin // 需要使用的的插件列表，如比例尺'AMap.Scale'等
            }).then((res) => {
                AMap = res;
                const { zoom, center, mapStyle } = { ...defaultOption, ...option };
                //基本地图加载
                this.map = new AMap.Map(el, {
                    resizeEnable: true,
                    center: center,
                    zoom: zoom,
                    mapStyle: "amap://styles/" + mapStyle,
                    version: "2.0",
                    ...option,
                    ...option.custom(AMap),
                });
                // 异步同时加载多个插件
                new AMap.plugin(mapPlugin, () => {
                    this.drawInnerLine();
                    this.drawOutLine();
                });
                resolve();
            });
        });
    } /**
     * @desc 中国外层边界线
     */,
    drawOutLine() {
        let geoJson = new AMap.GeoJSON({
            geoJSON: china,
            getPolygon: function(geoJson: string, lngLats: any) {
                return new AMap.Polyline({
                    path: lngLats[0],
                    strokeColor: "#2384dd",
                    strokeWeight: 3,
                    // lineJoin: 'round', //折线拐点的绘制样式
                    isOutline: false
                    // borderWeight: 2,
                    // outlineColor: '#6ccffe',
                });
            }
        });
        this.map.add(geoJson);
    } /**
     * @desc 中国内层边界线
     */,
    drawInnerLine() {
        let geoJson = new AMap.GeoJSON({
            geoJSON: chinaInner,
            getPolygon: function(geoJson: string, lngLats: any) {
                return new AMap.Polyline({
                    path: lngLats[0],
                    // strokeColor: '#57b2f8',
                    // strokeColor: '#2BA5FF',
                    // strokeColor: '#3d6eff',
                    // strokeWeight: 2,
                    // zIndex: 10,
                    isOutline: true,
                    outlineColor: "#2692fc",
                    borderWeight: 1,
                    strokeColor: "#88b9f8",
                    strokeWeight: 1,
                    strokeOpacity: 0.8
                });
            }
        });
        this.map.add(geoJson);
    },

};